<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN" "http://ibatis.apache.org/dtd/sql-map-2.dtd" >
<sqlMap namespace="com.uc.training.smadmin.gds.dao.HotTagDao">
    <!--查找热门商品标签-->
    <select id="selectHotTag" resultClass="com.uc.training.smadmin.gds.re.HotTagRE">
        SELECT
        tag.id,
        tag.tag
        FROM t_gds_hot_tag tag
        order by tag.sort_num asc
        limit 0, 10
    </select>

    <!-- 获取banner数量 -->
    <select id="getAdminHotTagCount" resultClass="java.lang.Long" parameterClass="com.uc.training.smadmin.gds.vo.AdminHotTagListVO">
        SELECT
        count(1)
        FROM t_gds_hot_tag s
        <dynamic prepend="where">
            <isNotEmpty property="tag" prepend="and">
                s.tag LIKE concat("%",#tag#,"%")
            </isNotEmpty>
        </dynamic>
    </select>

    <!-- 后台获取商品标签 -->
    <select id="getAllHotTagList" resultClass="com.uc.training.smadmin.gds.re.AdminHotTagListRE" parameterClass="com.uc.training.smadmin.gds.vo.AdminHotTagListVO">
        SELECT
        s.id AS id,
        s.tag AS tag,
        s.sort_num AS sortNum,
        s.create_time AS createTime,
        s.modify_time AS modifyTime
        FROM
          t_gds_hot_tag  s
        <dynamic prepend="where">
            <isNotEmpty property="tag" prepend="and">
                s.tag LIKE concat("%",#tag#,"%")
            </isNotEmpty>
        </dynamic>
        ORDER BY s.id ASC
        <isNotNull property="offset">
            limit #offset#, #pageSize#
        </isNotNull>
    </select>

    <!-- 更新 -->
    <update id="updateHotTag" parameterClass="com.uc.training.smadmin.gds.model.HotTag">
		 update t_gds_hot_tag  set
	   `tag` = #tag#, sort_num = #sortNum#, modify_emp = #modifyEmp#
		where id=#id#
	</update>

    <!-- 插入 -->
    <insert id="insertHotTag" parameterClass="com.uc.training.smadmin.gds.model.HotTag">
        insert into t_gds_hot_tag
        (tag, sort_num, create_emp,modify_emp)
        values (#tag#,#sortNum#,#createEmp#,#modifyEmp#)
        <selectKey keyProperty="id">
            select LAST_INSERT_ID() AS id
        </selectKey>
    </insert>

    <!--根据主键id删除标签-->
    <delete id="deleteHotTagById" parameterClass="Long">
		DELETE FROM t_gds_hot_tag WHERE id = #id#
	</delete>
</sqlMap>